/*
 * @Author: 脉迈
 * @Date: 2022-01-11 17:05:44
 * @LastEditors: 脉迈
 * @LastEditTime: 2022-01-18 14:23:06
 */
const Koa = require('koa');
// const { initRouter } = require('../../quark-h5/server/core/loader');
const {initConfig, initController, initRouter, initExtend, initMiddleware, initModels} = require('./loader');


class Application {
  constructor(){
    this.$app = new Koa();
    // 初始化配置
    this.$config = initConfig(this)
    // 初始化控制器
    this.$controller = initController(this);
    // 初始化middleware
		this.$middleware = initMiddleware(this);
    // 初始化路由
    this.$router = initRouter(this);
    this.$app.use(this.$router.routes());
    
    // 初始化拓展
    initExtend(this);

    // 初始化models
    this.$models = initModels()
  }
  // 启动服务
  start(port){
    this.$app.listen(port, ()=>{
      console.log('server is ing...')
    })
  }
}

module.exports = Application;